package org.example.model;

import java.time.LocalDateTime;

public class UserSession {
    private String userId;
    private String serverId;
    private String sessionId;
    private LocalDateTime connectTime;
    private LocalDateTime lastHeartbeatTime;
    private boolean active;

    public UserSession() {}

    public UserSession(String userId, String serverId, String sessionId) {
        this.userId = userId;
        this.serverId = serverId;
        this.sessionId = sessionId;
        this.connectTime = LocalDateTime.now();
        this.lastHeartbeatTime = LocalDateTime.now();
        this.active = true;
    }

    // Getters and Setters
    public String getUserId() { return userId; }
    public void setUserId(String userId) { this.userId = userId; }

    public String getServerId() { return serverId; }
    public void setServerId(String serverId) { this.serverId = serverId; }

    public String getSessionId() { return sessionId; }
    public void setSessionId(String sessionId) { this.sessionId = sessionId; }

    public LocalDateTime getConnectTime() { return connectTime; }
    public void setConnectTime(LocalDateTime connectTime) { this.connectTime = connectTime; }

    public LocalDateTime getLastHeartbeatTime() { return lastHeartbeatTime; }
    public void setLastHeartbeatTime(LocalDateTime lastHeartbeatTime) { this.lastHeartbeatTime = lastHeartbeatTime; }

    public boolean isActive() { return active; }
    public void setActive(boolean active) { this.active = active; }

    public void updateHeartbeat() {
        this.lastHeartbeatTime = LocalDateTime.now();
        this.active = true;
    }
}